package com.wf.smartcomm.server.serviceImpl;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.wf.smartcomm.server.config.UmConfig;
import com.wf.smartcomm.server.service.UmConfigService;
import com.wf.smartcomm.server.util.IdUtils;

@Service
@Transactional
public class UmConfigServiceImpl implements UmConfigService {

	@Resource
	private SessionFactory factory;
	
	@Override
	public void save(UmConfig config) {
		config.setObjectId(IdUtils.uuid());
		config.setCreatedAt(String.valueOf(System.currentTimeMillis()));
		factory.getCurrentSession().persist(config);
	}

	@Override
	@Transactional(propagation=Propagation.NOT_SUPPORTED)
	public UmConfig get(String id) {
		String hql = "from UmConfig where objectId =:id";
		Query query = factory.getCurrentSession().createQuery(hql);
		query.setParameter("id", id);
		return (UmConfig) query.uniqueResult();
	}
}
